﻿<%@ WebHandler Language="C#" Class="MangerAchievement" %>

using System;
using System.Web;
using System.Text;
using System.Collections.Generic;
using Chenxin.Lib.Utility;
using Chenxin.Lib.Business.BLL;

public class MangerAchievement : AjaxHandlerBase
{
    //*******************************************
    //功能概要       ：基本权限初始化设定
    //参数説明       ：-
    //返回值説明     ：-
    //功能詳細       ：权限哈希表中添加操作与权限组
    //作成者         ：he.jifeng 
    //作成日         ：2010-07-14
    //*******************************************
    public MangerAchievement()
    {
        //导出
        htTypePermit.Add("export", Constants.Permit_AchievementManger_Export);
    }

    //*******************************************
    //功能概要       ：请求处理
    //参数説明       ：context 请求上下文
    //返回值説明     ：-
    //功能詳細       ：根据请求名 分发请求
    //作成者         ：he.jifeng
    //作成日         ：2010-07-14
    //*******************************************
    override public void RequestProcess(HttpContext context)
    {
        try
        {
            context.Response.ContentType = "text/plain";
            context.Response.AddHeader("pragma", "no-cache");
            context.Response.AddHeader("cache-control", "");
            context.Response.CacheControl = "no-cache";

            string strOp = context.Request["op"];
            string strRet = string.Empty;
            switch (strOp.ToLower())
            {
                //业绩查询
                case "search":
                    strRet = GetMangerAchievement(context);
                    break;
                //业绩详细
                case "getdetail":
                    strRet = GetDetailAchievement(context);
                    break;
                default:
                    break;
            }
            context.Response.Write(strRet);
        }
        catch (Exception ex)
        {
            context.Response.Write(retExecResult(Constants.ExecResult.Error, ex.Message, ""));
        }
    }

    //*******************************************
    //功能概要       ：查询业绩
    //参数説明       ：context 请求上下文
    //返回值説明     ：响应信息
    //功能詳細       ：查询业绩
    //作成者         ：he.jifeng
    //作成日         ：2010-09-27
    //*******************************************
    private string GetMangerAchievement(HttpContext context)
    {
        string strRet = string.Empty;
        string strParam = string.Empty;
        StringBuilder strHtml = new StringBuilder();

        Dictionary<string, string> dicParams = new Dictionary<string, string>();
        ContractBaseInfo bllBaseInfo = new ContractBaseInfo();

        strParam = context.Request.Params["pagesize"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("PageSize", strParam);
        }
        strParam = context.Request.Params["pageindex"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("PageIndex", strParam);
        }
        strParam = context.Request.Params["sort"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("Sort", strParam);
        }
        strParam = context.Request.Params["StartTime"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("StartTime", strParam);
        }
        strParam = context.Request.Params["EndTime"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("EndTime", strParam);
        }
        strParam = context.Request.Params["BusinessType"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("BusinessType", strParam);
        }
        strParam = context.Request.Params["UserObjectId"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("UserObjectId", strParam);
        }
      
        if (!string.IsNullOrEmpty(context.Request.Params["departid"]))
        {
            dicParams.Add("DepartId", context.Request.Params["departid"]);
        }
        else if (!string.IsNullOrEmpty(context.Request.Params["areaid"]))
        {
            dicParams.Add("AreaId", context.Request.Params["areaid"]);
        }
        else if (!string.IsNullOrEmpty(context.Request.Params["companyid"]))
        {
            dicParams.Add("CompanyId", context.Request.Params["companyid"]);
        }
        if (!string.IsNullOrEmpty(context.Request.Params["cityid"]))
        {
            dicParams.Add("CityId", context.Request.Params["cityid"]);
        }
        else
        {
            dicParams.Add("CompanyId", CurrentUserInfo.CompanyId.ToString());
        }

        System.Data.DataSet dsBaseInfo = bllBaseInfo.GetMangerCollAchievementByParams(dicParams);

        strHtml.Append("{");
        strHtml.Append("success:'1',");
        strHtml.Append("msg:'',");
        strHtml.AppendFormat("data:{{{0},", JsonHelp.Convert2Json(dsBaseInfo.Tables[0]));
        strHtml.AppendFormat("count:'{0}'", dsBaseInfo.Tables[1].Rows[0][0]);
        strHtml.Append("}");
        strHtml.Append("}");

        strRet = strHtml.ToString();

        return strRet;
    }

    //*******************************************
    //功能概要       ：查询业绩详情
    //参数説明       ：context 请求上下文
    //返回值説明     ：响应信息
    //功能詳細       ：查询业绩详情
    //作成者         ：he.jifeng
    //作成日         ：2010-09-27
    //*******************************************
    private string GetDetailAchievement(HttpContext context)
    {
        string strRet = string.Empty;
        string strParam = string.Empty;
        StringBuilder strHtml = new StringBuilder();

        Dictionary<string, string> dicParams = new Dictionary<string, string>();
        ContractBaseInfo bllBaseInfo = new ContractBaseInfo();

        strParam = context.Request.Params["pagesize"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("PageSize", strParam);
        }
        strParam = context.Request.Params["pageindex"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("PageIndex", strParam);
        }
        strParam = context.Request.Params["sort"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("Sort", strParam);
        }
        strParam = context.Request.Params["StartTime"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("StartTime", strParam);
        }
        strParam = context.Request.Params["EndTime"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("EndTime", strParam);
        }
        strParam = context.Request.Params["UserObjectId"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("UserObjectId", strParam);
        }
        strParam = context.Request.Params["BusinessType"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("BusinessType", strParam);
        }
        strParam = context.Request.Params["EmployeeId"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("UserId", strParam);
        }

        System.Data.DataSet dsBaseInfo = bllBaseInfo.GetMangerAchievementByParams(dicParams);

        strHtml.Append("{");
        strHtml.Append("success:'1',");
        strHtml.Append("msg:'',");
        strHtml.AppendFormat("data:{{{0},", JsonHelp.Convert2Json(dsBaseInfo.Tables[0]));
        strHtml.AppendFormat("count:'{0}'", dsBaseInfo.Tables[1].Rows[0][0]);
        strHtml.Append("}");
        strHtml.Append("}");

        strRet = strHtml.ToString();

        return strRet;
    }
}